package org.xtext.tcc.generator;

import com.google.inject.Inject;
import org.eclipse.emf.common.util.EList;
import org.eclipse.emf.ecore.EObject;
import org.eclipse.xtext.naming.IQualifiedNameProvider;
import org.eclipse.xtext.naming.QualifiedName;
import org.eclipse.xtext.xbase.lib.StringExtensions;
import org.eclipse.xtext.xtend2.lib.StringConcatenation;
import org.xtext.tcc.TccdslExtensions;
import org.xtext.tcc.tccdsl.Entity;
import org.xtext.tcc.tccdsl.Function;

@SuppressWarnings("all")
public class ControllerExtensions extends TccdslExtensions {
  
  @Inject
  private IQualifiedNameProvider nameProvider;
  
  public StringConcatenation control(final Entity e) {
    StringConcatenation _builder = new StringConcatenation();
    {
      EObject _eContainer = e.eContainer();
      if ((_eContainer instanceof org.xtext.tcc.tccdsl.Package)) {
        _builder.append("package ");
        String _packageName = this.packageName(e);
        _builder.append(_packageName, "");
        _builder.append(".control;");
        _builder.newLineIfNotEmpty();} else {
        _builder.append("package control;");
        _builder.newLine();
      }
    }
    _builder.newLine();
    _builder.append("import java.util.List;");
    _builder.newLine();
    _builder.append("import ");
    QualifiedName _fullyQualifiedName = this.nameProvider.getFullyQualifiedName(e);
    _builder.append(_fullyQualifiedName, "");
    _builder.append(";");
    _builder.newLineIfNotEmpty();
    _builder.newLine();
    _builder.append("public class ");
    String _name = e.getName();
    String _firstUpper = StringExtensions.toFirstUpper(_name);
    _builder.append(_firstUpper, "");
    _builder.append("Controller{");
    _builder.newLineIfNotEmpty();
    {
      EList<Function> _functions = e.getFunctions();
      for(Function f : _functions) {
        _builder.append("\t");
        _builder.newLine();
        _builder.append("\t");
        _builder.append("public static ");
        StringConcatenation _functionHeader = this.functionHeader(f);
        _builder.append(_functionHeader, "	");
        _builder.append("{");
        _builder.newLineIfNotEmpty();
        _builder.append("\t");
        _builder.append("\t");
        _builder.newLine();
        _builder.append("\t");
        _builder.append("}");
        _builder.newLine();
      }
    }
    _builder.append("}");
    _builder.newLine();
    return _builder;
  }
}